package game.util.sosc;

import java.awt.Color;

import game.gfx.ConsoleColor;
import game.util.Util;

public class ConsoleColorConverter implements IStringObjectStringConverter<ConsoleColor>
{
    @Override
    public ConsoleColor toObject(String string)
    {
        String foreground = string.substring("foreground=".length(), string.indexOf(",background="));
        String background = string.substring(string.lastIndexOf("=") + 1);
        return new ConsoleColor(Util.toObject(foreground, Color.class),
                                Util.toObject(background, Color.class));
    }

    @Override
    public String toString(ConsoleColor object)
    {
        StringBuilder string = new StringBuilder();
        string.append("foreground=").append(Util.toString(object.getForeground()));
        string.append(",background=").append(Util.toString(object.getBackground()));
        return string.toString();
    }
}